<template>
  <div>
    <el-row :gutter="20" type="flex" justify="center" style="padding: 34px;">
      <el-col :span="8" :offset="0">
        <el-card shadow="always" style="height:100px;width:390px;">
          <div style="float:left;color:#409EFF;">
            <svg-icon icon-class="user">
              <use :xlink:href="user" />
            </svg-icon>
          </div>
          <div style="float:right">
            <span style="float:top" class="card-panel-text">用户总数</span>
            <div style="font-weight: 900;">{{ user }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6" :offset="0">
        <el-card shadow="always" style="height:100px;width:390px;">
          <div style="float:left;color:#409EFF;">
            <svg-icon icon-class="messages">
              <use :xlink:href="messages" />
            </svg-icon>
          </div>
          <div style="float:right">
            <span style="float:top" class="card-panel-text">商品总数</span>
            <div style="font-weight: 900;">{{ goods }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6" :offset="0">
        <el-card shadow="always" style="height:100px;width:390px;">
          <div style="float:left;color:#409EFF;">
            <svg-icon icon-class="money">
              <use :xlink:href="money" />
            </svg-icon>
          </div>
          <div style="float:right">
            <span style="float:top" class="card-panel-text">Purchases</span>
            <div style="font-weight: 900;">9,890</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6" :offset="0">
        <el-card shadow="always" style="height:100px;width:390px;">
          <div style="float:left;color:#409EFF;">
            <svg-icon icon-class="shopping">
              <use :xlink:href="shopping" />
            </svg-icon>
          </div>
          <div style="float:right">
            <span style="float:top" class="card-panel-text">订单数量</span>
            <div style="font-weight: 900;">{{ order }}</div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <div>
      <el-row :gutter="20" type="flex" justify="center" style="padding: 34px;">

        <el-col :span="80" :offset="0">
          <el-card shadow="always" style="height:600px;width:790px;">
            <div style="float:left;">
              <span id="myChart" :style="{width: '600px', height: '600px'}" />

            </div>
          </el-card>
        </el-col>
        <el-col :span="80" :offset="0">
          <el-card shadow="always" style="height:600px;width:790px;">
            <div style="float:right">
              <span style="float:top" class="card-panel-text">
                <span id="myChart2" :style="{width: '600px', height: '600px'}" />

              </span>
            </div>
          </el-card>
        </el-col>

      </el-row>

    </div>
  </div>

</template>

<script>
import { mapGetters } from 'vuex'
import { userCount } from '@/api/system/user'
import { orderCount } from '@/api/order/index'
import { goodsCount } from '@/api/goods/index'
// 引入基本模板
const echarts = require('echarts')
// 引入柱状图组件
require('echarts/lib/chart/bar')
// 引入提示框和title组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
export default {
  name: '',
  components: {
  },
  data() {
    return {

      user: '',
      order: '',
      shopping: '',
      messages: '',
      money: '',
      goods: ''
    }
  },
  computed: {
    ...mapGetters([

    ])
  },
  created() {
    this.queryUserCount()
    this.queryOrderCount()
    this.goodsCount()
  },
  mounted() {
    this.drawLine()
  },
  methods: {
    queryUserCount() {
      userCount().then(
        response => {
          this.user = response.data
        }
      )
    },
    queryOrderCount() {
      orderCount().then(
        response => {
          this.order = response.data
        }
      )
    },
    goodsCount() {
      goodsCount().then(
        response => {
          this.goods = response.data
        }
      )
    },
    drawLine() {
      // 基于准备好的dom，初始化echarts实例
      const myChart = echarts.init(document.getElementById('myChart'))
      // 绘制图表
      myChart.setOption({
        title: { text: '商品销量', x: 'center' },
        tooltip: {},
        xAxis: {
          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [{
          name: '销量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
        }]
      })
      const myChart2 = echarts.init(document.getElementById('myChart2'))
      // 绘制图表
      myChart2.setOption({
        title: { text: '用户访问来源', x: 'center' },
        tooltip: {},
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: '55%',
            data: [
              { value: 235, name: '视频广告' },
              { value: 274, name: '联盟广告' },
              { value: 310, name: '邮件营销' },
              { value: 335, name: '直接访问' },
              { value: 400, name: '搜索引擎' }
            ]
          }
        ]
      })
    }
  }

}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}

.svg-icon {
    width: 3em;
    height: 3em;
    vertical-align: -0.15em;
    //fill: currentColor!important;
    overflow: hidden;
  }
  .card-panel-text {
    color: rgba(0,0,0,.45);
    font-size: 16px;
    margin-bottom: 22px;
  }
</style>
